#include "pop_ball_task.h"
#include "pop_ball.h"
#include "FreeRTOS.h"
#include "task.h"
#include "cmsis_os.h"



uint8_t run_flag;
uint8_t inverse_flag;
//uint8_t stop_flag;

uint8_t op_pump_flag = 0;
uint8_t cl_pump_flag = 0;
uint8_t go_pump_flag = 0;
uint8_t back_pump_flag = 0; 


uint8_t allow_shoot_flag = 0;

void StartPopBallTask(void *argument);
osThreadId_t	popBallTaskHandle;		//电机调速任务（速度环pid调速）
const osThreadAttr_t popBallTask_attributes = {
  .name = "popBallTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal,		//优先级normal
};

void pop_ball_task_init(void)
{
	popBallTaskHandle = osThreadNew(StartPopBallTask, NULL, &popBallTask_attributes);
}

void StartPopBallTask(void *argument)
{
	for(;;)
	{
		
		
		//air
		if(op_pump_flag == 1)
		{
			if(allow_shoot_flag==1)
			{
				down_pump();    //向下拍击
			}
			
			open_pump();	//打开爪子
			
			if(allow_shoot_flag==1)
			{
				up_pump();      //拍击收回
			}
			if(allow_shoot_flag==1)
			{
				vTaskDelay(pdMS_TO_TICKS(290));
				close_pump();	//关闭爪子
			}

			
			op_pump_flag = 0;
		}
		if(cl_pump_flag == 1)
		{
			
			close_pump();	//关闭爪子
			cl_pump_flag = 0;
		}
		
		if(go_pump_flag == 1)
		{
			
			go_pump();
			allow_shoot_flag=1;
			go_pump_flag = 0;
		}
		
		if(back_pump_flag == 1)
		{
			
			back_pump();
			allow_shoot_flag=0;
			back_pump_flag = 0;
		}
		
		osDelay(1);
	}
}


